package m.store.model;

import m.common.model.*;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@TableMeta(name = "ts_stock_info", description = "库存信息")
public class StockInfo extends OrderModel implements MigrationModel {
    @Override
    public List<String> migrationOidList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(this.getClass(),new String[]{"oid"},null,
                        QueryCondition.eq("store.oid",storeOid))
                .stream().map(Model::getOid).collect(Collectors.toList());
    }
    @FieldMeta(name="stock_date",type= FieldType.DATE,description="入库日期")
    private Date stockDate;
    @FieldMeta(name="stock_amount",type= FieldType.DOUBLE,defaultValue = "0",description="库存金额|明细库存金额汇总")
    private Double stockAmount;
    @FieldMeta(name = "remark",type = FieldType.STRING,length = 1000,description = "备注")
    private String remark;
    @FieldMeta(name="in_pay_amount",type= FieldType.DOUBLE,defaultValue = "0",description="付款中金额")
    private Double inPayAmount;

    @FieldMeta(name="type",type= FieldType.STRING,defaultValue = "A",description="类型",dictOption = "A:正常入库,B:调拨入库,C:生产入库,D:盘点入库,R:出库退货,Z:期初入库,V:虚拟库存,S:服务项目")
    private String type;
    public final static String Type_Stock="A";
    public final static String Type_Allocate="B";
    public final static String Type_Produce="C";
    public final static String Type_Count="D";
    public final static String Type_Refund="R";
    public final static String Type_Begin="Z";
    public final static String Type_Virtual="V";
    public final static String Type_Server="S";
    @LinkTableMeta(name="refund_sale_oid",table= SaleInfo.class,description="退出库")
    private SaleInfo refundSale;
    @FieldMeta(name="refund_amount",type= FieldType.DOUBLE,defaultValue = "0",description="退款金额")
    private Double refundAmount;
    //冗余信息
    @FieldMeta(name="pay_status",type= FieldType.STRING,defaultValue = "N",description="付款状态",dictOption = "N:未付款,A:部分付款,Y:已付款,W:无需付款")
    private String payStatus;
    @FieldMeta(name="pay_amount",type= FieldType.DOUBLE,defaultValue = "0",description="付款金额|付款记录金额汇总")
    private Double payAmount;
    @FieldMeta(name="owe_amount",type= FieldType.DOUBLE,defaultValue = "0",description="尚欠金额|欠客户：库存金额-退款金额-付款金额，退出库无需付款尚欠0")
    private Double oweAmount;

    public Date getStockDate() {
        return stockDate;
    }

    public void setStockDate(Date stockDate) {
        this.stockDate = stockDate;
    }

    public Double getStockAmount() {
        return stockAmount;
    }

    public void setStockAmount(Double stockAmount) {
        this.stockAmount = stockAmount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Double getInPayAmount() {
        return inPayAmount;
    }

    public void setInPayAmount(Double inPayAmount) {
        this.inPayAmount = inPayAmount;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public SaleInfo getRefundSale() {
        return refundSale;
    }

    public void setRefundSale(SaleInfo refundSale) {
        this.refundSale = refundSale;
    }

    public Double getRefundAmount() {
        return refundAmount;
    }

    public void setRefundAmount(Double refundAmount) {
        this.refundAmount = refundAmount;
    }

    public String getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(String payStatus) {
        this.payStatus = payStatus;
    }

    public Double getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(Double payAmount) {
        this.payAmount = payAmount;
    }

    public Double getOweAmount() {
        return oweAmount;
    }

    public void setOweAmount(Double oweAmount) {
        this.oweAmount = oweAmount;
    }
}
